﻿<?php
/**
 * 轻云网络验证系统
 * =======================================================
 * 版权所有(C) 2019-2039 daenx.cn，并保留所有权利。
 * 作者：Daen大恩
 * 作者QQ: 1330166565
 * 开发群：661059773
 * =======================================================
 */

include 'data/weby.php';
$username=$_GET["username"];
$domain=$_GET["domain"];
$qq=$_GET["qq"];
$km=$_GET["km"];
$nowtime=time();
$pass=$_GET["pass"];

if($_GET[submit]=="确定充值"){
	if($domain==""){
		header('Content-type:text/html;charset=utf-8');
		echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">授权账号不能为空!</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'self-km.php' });  }});</script>");
	}else{
		header('Content-type:text/html;charset=utf-8');
		if($km==""){
			header('Content-type:text/html;charset=utf-8');
			echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">卡密不能为空!</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'self-km.php' });  }});</script>");
		}else{
			if($km=="admin"){
				header('Content-type:text/html;charset=utf-8');
				echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">卡密有误或无法使用!</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'self-km.php' });  }});</script>");
			}else{
			$sql="SELECT * FROM `cami` where km='$km' limit 1";//判断卡密
			$row=mysqli_fetch_array(mysqli_query($con,$sql));
			if($row){
				//添加授权
				$yme=$row['ytime'];
				$cp=$row['cp'];		
				$kmid=$row[id];
				
				
				mysqli_select_db($dbname);
				mysqli_query($con,"set names utf8");
				$sql="select * from authorize where domain='$domain' and ycp='$cp'";
				$query=mysqli_query($con,$sql);
				$rows = mysqli_num_rows($query);
				$row=mysqli_fetch_assoc($query);
				
				if($rows > 0){
					if($row['time']=="free")
						{$time = strtotime($yme);}
					else
						{
						if(time() > $row['time'])
						{
							$time = strtotime($yme);
						}else
						{$time = strtotime($yme,$row['time']);}
					}
					$sql = "UPDATE `authorize` SET `time` = '$time' WHERE domain='$domain' and ycp='$cp';";
					mysqli_query($con,$sql); 
			
					}else{
					
					echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">未查询到账号".$domain."<br>请先注册！</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'self-km.php' });  }});</script>");
					die(); 
				}
				if($time == null){$dsc="永久";}
				else{$dsc=date("Y-m-d",$time);}
				mysqli_query($con,"DELETE FROM `cami` where `id` = $kmid ");//删除卡密
				header('Content-type:text/html;charset=utf-8');
				echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '280px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">充值成功<br>账号：".$domain."<br>产品：".$cp."<br>到期日期：".$dsc."</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'self-km.php' });  }});</script>");
				$status = '已使用';
				$status = base64_encode($status);
				$sql = "INSERT INTO `camilog` (`domain`, `km`, `time`,  `status`,  `ytime`,`cp`) VALUES ('$domain', '$km', '$nowtime', '$status', '$yme','$cp');";
				mysqli_query($con,$sql);
				
					
				}else{
					
					$sql="SELECT * FROM `cami_ye` where km='$km' limit 1";//判断卡密
			$row=mysqli_fetch_array(mysqli_query($con,$sql));
			if($row){
				//添加授权
				$ye=$row['ye'];
				$cp=$row['cp'];		
				$kmid=$row[id];
				
				
				mysqli_select_db($dbname);
				mysqli_query($con,"set names utf8");
				$sql="select * from authorize where domain='$domain' and ycp='$cp'";
				$query=mysqli_query($con,$sql);
				$rows = mysqli_num_rows($query);
				$row=mysqli_fetch_assoc($query);
				
				if($rows > 0){
					$zye = $row['rmb'] + $ye;
					
					$sql = "UPDATE `authorize` SET `rmb` = '$zye' WHERE domain='$domain' and ycp='$cp';";
					mysqli_query($con,$sql); 
			//echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">续费!</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'self-km.php' });  }});</script>");
				}else{
					echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">未查询到账号".$domain."<br>请先注册！</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'self-km.php' });  }});</script>");
					die(); 
				}
				
				
					mysqli_query($con,"DELETE FROM `cami_ye` where `id` = $kmid ");//删除卡密
					$status = '已使用';
					$status = base64_encode($status);
					$sql = "INSERT INTO `camilog` (`domain`, `km`, `time`,  `status`,  `ytime`,`cp`) VALUES ('$domain', '$km', '$nowtime', '$status', '$ye','$cp');";
					mysqli_query($con,$sql);
					$ip = getip();
					$sql = "INSERT INTO `log_rmb` (`domain`,`time`,`cp`,`rmb`,`zrmb`,`bz`,`ip`) VALUES ('$domain', '$nowtime', '$cp', '+$ye', '$zye', '网页使用-余额卡密','$ip');";//添加流水日志
					mysqli_query($con,$sql);
					header('Content-type:text/html;charset=utf-8');
					echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '280px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">充值成功<br>账号：".$domain."<br>产品：".$cp."<br>现有余额：".$zye."</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'self-km.php' });  }});</script>");
					
					
				}else{
					header('Content-type:text/html;charset=utf-8');
					echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">卡密错误或者已被使用!</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'self-km.php' });  }});</script>");
				}
			}
		}
	}
}}
mysqli_close();

?>
<?php
include 'head.php';
?>

    <title>卡密充值-<?php echo $title?></title>
<link rel="shortcut icon" href="<?php echo $route?>img/LightCloud.png" type="image/x-icon" />
    <!-- Bootstrap core CSS -->
    <link href="<?php echo $route?>css/bootstrap.min.css" rel="stylesheet">
    <link href="<?php echo $route?>css/bootstrap-reset.css" rel="stylesheet">
    <!--external css-->
    <link href="<?php echo $route?>font-awesome/css/font-awesome.css"  rel="stylesheet"/>
    <!-- Custom styles for this template -->
    <link href="<?php echo $route?>css/style.css"  rel="stylesheet">
    <link href="<?php echo $route?>css/style-responsive.css" rel="stylesheet"/>
    <!--toastr-->
    <link href="<?php echo $route?>toastr-master/toastr.css" rel="stylesheet" type="text/css"/>
    <script language="JavaScript" src="<?php echo $route?>js/jquery-1.7.2.min.js"></script>
    <script language="JavaScript" src="<?php echo $route?>js/function.js"></script>
    <!-- HTML5 shim and Respond.js IE8 support of HTML5 tooltipss and media queries -->
    <!--[if lt IE 9]>
    <script src="<?php echo $route?>js/html5shiv.js" ></script>
    <script src="<?php echo $route?>js/respond.min.js" ></script>
    <![endif]-->
	<style>
	body{
		margin: 0 auto;
		text-align: center;
	}
	.container {
	  max-width: 580px;
	  padding: 15px;
	  margin: 0 auto;
	}
	.hzhz{
		float: left;
	}
	.bzbz {
	color: #31708f;
	background-color: rgba(217, 237, 247, 0.73);
	border-color: #bce8f1;

	padding: 15px;
	margin-bottom: 20px;
	border: 1px solid transparent;
	border-radius: 3px;
	}
	.form-controltm {
	display: block;
	width: 100%;
	height: 34px;
	padding: 6px 12px;
	font-size: 14px;
	line-height: 1.42857143;
	color: #555;
	background-color: rgba(255, 255, 255, 0.48);
	background-image: none;
	border: 1px solid #ccc;
	border-radius: 4px;
	-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
	box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
	-webkit-transition: border-color ease-in-out .15s, -webkit-box-shadow ease-in-out .15s;
	-o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
	transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
	}

	.alert-dangergg {
	color: #a94442;
	background-color: #f2dede;
	border-color: #ebccd1;

	padding: 15px;
	margin-bottom: 20px;
	border: 1px solid transparent;
	border-radius: 4px;
	}
	</style>
</head>

<body >

<section id="container" >

    <section id="main-content">
        <section class="wrapper">
           <div class="row">
<div class="col-md-6 col-md-offset-2">
                    <!--work progress start-->
                    <section class="panel">
                        <div class="panel-body progress-panel">
                            <div class="task-progress">
                                <h1>卡密充值</h1>
                                
                            </div>
                        </div>
						<div class="table  table-hover personal-task">
							<ul class="pagination"><a class="btn btn-info" href="index.php">用户查询</a> &nbsp;<a class="btn btn-primary" href="self-zc.php">用户注册</a> &nbsp;<a class="btn btn-success" href="self-km.php">卡密充值</a> &nbsp;<a class="btn btn-warning" href="<?php echo $website; ?>" target="_blank">购买卡密</a></ul>
							<div class="alert-dangergg">
                        			<?php echo $prompt; ?>	</div>
                        		 <br>
							
	 <h3 class="form-signin-heading">输入相关信息</h3>
	 <form action="self-km.php" class="form-sign" method="get"><input type="hidden" name="self" value="6" />
	 (余额卡密和期限卡密多可以在此充值，卡密类型和所属产品会自动识别)<br><br>
		 <input type="text" class="form-controltm" name="domain" placeholder="请输入账号，必填" value="" required><br>
		 <input type="text" class="form-controltm" name="km" placeholder="请输入您的卡密，必填" value="" required><br>
		 <input type="submit" name="submit" class="btn btn-danger btn-block" value="确定充值">
	 </form>
<br/>
<br/>
<br/>
<?php
include "search.php";
?>	
                        <div class="container-fluid"> 
								<a href="<?php echo $website; ?>" target="_blank" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-credit-card"></span> 购买</a> 
								<a class="btn btn-success" href="user.php">自助后台</a>
								<a class="btn btn-primary" href="user">代理后台</a>&nbsp;<a class="btn btn-danger" href="center">系统后台</a>
							<a href="http://wpa.qq.com/msgrd?v=3&amp;uin=<?php echo $kfqq; ?>&amp;site=qq&amp;menu=yes" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-pencil"></span> 客服</a> </div>
   <p style="text-align:center"><br>&copy; Powered by <?php echo $title?></p></div>

                    </section>
                    <!--work progress end-->
                </div>
				

        </section>
    </section>
    <!--main content end-->
</section>


<!-- js placed at the end of the document so the pages load faster -->
<script src="<?php echo $route?>js/jquery.js" ></script>
<script src="<?php echo $route?>js/bootstrap.min.js" ></script>
<!--toastr-->
<script src="<?php echo $route?>toastr-master/toastr.js" ></script>

<script type="text/javascript" src="<?php echo $route?>jCryption/jquery.jcryption.3.1.0.js" ></script>


</body>
</html>